Dynomotion

Group: DynoMotion Message: 11691 From: moray_cuthill Date: 6/13/2015
Subject: Adding a DRO to KMotionCNC/ATC coding
Are there any examples for taking a persistent var from the KFlop and displaying it in KMotionCNC?
Specifically I want to show the current turret position from the relevant persistent/user var, and have it show on the screen next to the current tool slot/id value.

Also, is there any issue with relying on While loops to wait for input changes within the ATC script? I know it could lead to a lock up if the required input doesn't happen, but is there any other major reason to avoid this technique?
I will probably redo the script to include timeouts, but I'd just like to get it working similar to how I had the Mach Macro working before altering things too much (If it hanged Mach, hitting stop would kill the locked macro, so it was never a major issue, but will the same work)

What's the best way to kill the ATC thread and halt

 KMotionCNC if a fault is detected? Would triggering an EStop be the simplest option?

Thanks,
Moray
Group: DynoMotion Message: 11693 From: Hardy Family Date: 6/13/2015
Subject: Re: Adding a DRO to KMotionCNC/ATC coding


On Sat, Jun 13, 2015 at 8:12 AM, moray.cuthill@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Are there any examples for taking a persistent var from the KFlop and displaying it in KMotionCNC?
Specifically I want to show the current turret position from the relevant persistent/user var, and have it show on the screen next to the current tool slot/id value.

I think you would need to add a user interface element, and modify the application code to update it.  Persist vars 100-107 are always updated and available to the app from the bulk status message.  I haven't tried this, so YMMV.
 

Also, is there any issue with relying on While loops to wait for input changes within the ATC script? I know it could lead to a lock up if the required input doesn't happen, but is there any other major reason to avoid this technique?

I deal with this by writing a function which sets a timeout and also waits for the move to complete.  Typically, it also looks for some other conditions such as estop.  The function returns 0 if everything was OK, or -1 otherwise.  Something like this:

int wait_io_high(int io, double timeout)
{
  double T = Time_sec() + timeout;
  while (Time_sec() < T) {
    if (ReadBit(io))
      return 0;
    // examples of tests for conditions which might prevent the
    // i/o from getting set...
    if (!chan[0].Enable)
      return -1;  // X axis got disabled e.g. following error
    // any other tests required...

    // finally, be nice and don't hog the CPU...
    WaitNextTimeSlice();
  }
  return -1; // timed out
}

The important thing is to be consistent in using the wrapper functions and doing something sensible with the result, otherwise if your thread "locks up" then you'll spend a lot of time looking for the bug.  Since the C compiler doesn't support linking, putting all these little routines in a c file which you then #include into your main thread code promotes re-use and consistency.

Using the wrapper functions and handling the results can make the code look somewhat ugly, but it's better than not working. 

I would request that Tom consider adding C's setjmp()/longjmp() functions to the firmware, since it makes this sort of exception handling a lot cleaner.  Programming machine control really has to handle a lot of exceptional conditions (as you are aware) so anything which helps keep the code clean and maintainable is a plus.
 
I will probably redo the script to include timeouts, but I'd just like to get it working similar to how I had the Mach Macro working before altering things too much (If it hanged Mach, hitting stop would kill the locked macro, so it was never a major issue, but will the same work)

What's the best way to kill the ATC thread and halt

According to Tom, PauseThread() effectively kills a thread if you start it from scratch next time (rather than resuming it).
 

 KMotionCNC if a fault is detected? Would triggering an EStop be the simplest option?

I found that telling K-CNC to estop caused too much pain.  It goes and kills every thread on the kflop.  This may be what you want, but it may be a bit drastic.  I prefer to use the "halt" command, which stops the g-code from proceeding but leaves threads running on the kflop.

Regards,
SJH

 

Thanks,
Moray


Group: DynoMotion Message: 11694 From: Tom Kerekes Date: 6/13/2015
Subject: Re: Adding a DRO to KMotionCNC/ATC coding
Hi Moray,

You can read persistent variables from KFLOP with the Script Command "GetPersistDec".  To display it on the screen you might look at how the current tool slot is displayed.  Unfortunately it isn't easy with MFC.

While loops are not a problem if a separate Thread is used for Tool Changes.  User Threads can not block other Threads or KFLOP System tasks.  Only the current Thread will be blocked and all others get their full time slice regardless.  A call to WaitNextTimeSlice() simply blocks for the remainder of the time slice.  It wont provide any additional time for other Threads.  The benefit of using WaitNextTimeSlice is to have periodic execution and to get a period of time where the code will not be interrupted.  See:

KMotionCNC will kill all Threads (except Thread #1) on STOP.   But the best approach is to monitor for error conditions, return error codes, optionally halt execution, and exit on error conditions.  I think as with any programming environment well handling of errors is often more complex than normal tasks.

HTH
Regards
TK

Group: DynoMotion Message: 11699 From: Moray Cuthill Date: 6/14/2015
Subject: Re: Adding a DRO to KMotionCNC/ATC coding
Thanks for the replies.

I'll have a go at modifying the KMotionCNC screen.
I'd also like to add a screen that shows the complete PLC status, as it would help, but I suspect that may be a step too far at this time.
I'm going to have a bit hotel time this week, so I'll see how I get on with getting all the scripts converted from Mach.


Out of curiosity, for those who've designed their own screens/programs, what language have you been using?
I may have ago at making my own program, however I suspect the pain of modifying KMotionCNC may be the more tolerable option..

Thanks,
Moray


On Sat, Jun 13, 2015 at 9:24 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi Moray,

You can read persistent variables from KFLOP with the Script Command "GetPersistDec".  To display it on the screen you might look at how the current tool slot is displayed.  Unfortunately it isn't easy with MFC.

While loops are not a problem if a separate Thread is used for Tool Changes.  User Threads can not block other Threads or KFLOP System tasks.  Only the current Thread will be blocked and all others get their full time slice regardless.  A call to WaitNextTimeSlice() simply blocks for the remainder of the time slice.  It wont provide any additional time for other Threads.  The benefit of using WaitNextTimeSlice is to have periodic execution and to get a period of time where the code will not be interrupted.  See:

KMotionCNC will kill all Threads (except Thread #1) on STOP.   But the best approach is to monitor for error conditions, return error codes, optionally halt execution, and exit on error conditions.  I think as with any programming environment well handling of errors is often more complex than normal tasks.

HTH
Regards
TK